package ml.uuku.oschub.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import ml.uuku.oschub.adpater.BlogAdapter;
import ml.uuku.oschub.api.remote.OSChinaApi;
import ml.uuku.oschub.base.BaseListFragment;
import ml.uuku.oschub.bean.Blog;
import ml.uuku.oschub.bean.BlogList;
import ml.uuku.oschub.interf.OnTabReselectListener;
import ml.uuku.oschub.util.XmlUtils;

import java.io.InputStream;
import java.io.Serializable;

/**
 * 博客区中单一模块的展示
 * 
 * @author kymjs(kymjs123@gmail.com)
 */
public class BlogFragment extends BaseListFragment<Blog> implements
        OnTabReselectListener {

    public static final String BUNDLE_BLOG_TYPE = "BUNDLE_BLOG_TYPE";

    protected static final String TAG = BlogFragment.class.getSimpleName();
    private static final String CACHE_KEY_PREFIX = "bloglist_";

    private String blogType;

    @Override
    protected BlogAdapter getListAdapter() {
        return new BlogAdapter();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            blogType = args.getString(BUNDLE_BLOG_TYPE);
        }
    }

    @Override
    protected BlogList parseList(InputStream is) throws Exception {
        BlogList list = XmlUtils.toBean(BlogList.class, is);
        return list;
    }

    @Override
    protected BlogList readList(Serializable seri) {
        return ((BlogList) seri);
    }

    @Override
    protected void sendRequestData() {
        OSChinaApi.getBlogList(blogType, mCurrentPage, mHandler);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

    }

    @Override
    public void onTabReselect() {
        onRefresh();
    }

}
